{"ast":null,"code":"import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from'react';import{format,isToday,fromUnixTime,formatDistanceToNow}from\"date-fns\";import ruLocale from\"date-fns/locale/ru\";import{jsx as _jsx}from\"react/jsx-runtime\";import{jsxs as _jsxs}from\"react/jsx-runtime\";var getMessageTime=function getMessageTime(date){if(isToday(date)){return format(date,'HH:mm');}else{return format(date,'d.MM.yy');}};var Date=function Date(_ref){var message=_ref.message,_ref$shortDate=_ref.shortDate,shortDate=_ref$shortDate===void 0?false:_ref$shortDate;var _React$useState=React.useState(0),_React$useState2=_slicedToArray(_React$useState,2),dateTime=_React$useState2[0],setDateTime=_React$useState2[1];React.useEffect(function(){if(message.updatedAt){setDateTime(message.updatedAt);}else if(message.createdAt){setDateTime(message.createdAt);}},[]);return/*#__PURE__*/_jsxs(\"span\",{className:\"message__date\",children:[message.updatedAt&&!shortDate&&/*#__PURE__*/_jsx(\"p\",{className:\"message__date--updateData\",children:\"\\u043E\\u0431\\u043D\\u043E\\u0432\\u043B\\u0435\\u043D\\u043E \"+formatDistanceToNow(fromUnixTime(dateTime),{addSuffix:true,locale:ruLocale})}),!message.updatedAt&&message.createdAt&&!shortDate&&/*#__PURE__*/_jsx(\"p\",{className:\"message__date--createData\",children:\"\\u043E\\u0442\\u043F\\u0440\\u0430\\u0432\\u043B\\u0435\\u043D\\u043E \"+formatDistanceToNow(fromUnixTime(dateTime),{addSuffix:true,locale:ruLocale})}),shortDate&&/*#__PURE__*/_jsx(\"p\",{className:\"message__date--lastMessage\",children:getMessageTime(fromUnixTime(dateTime))})]});};export default Date;","map":{"version":3,"names":["React","format","isToday","fromUnixTime","formatDistanceToNow","ruLocale","getMessageTime","date","Date","message","shortDate","useState","dateTime","setDateTime","useEffect","updatedAt","createdAt","addSuffix","locale"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/components/Message/Date/index.tsx"],"sourcesContent":["import React from 'react';\nimport {MessageDateProps} from \"../../../models/props/MessageDateProps\";\nimport {format, isToday, fromUnixTime, formatDistanceToNow} from \"date-fns\";\nimport ruLocale from \"date-fns/locale/ru\";\n\nconst getMessageTime = (date: Date): string => {\n    if (isToday(date)) {\n        return format(date, 'HH:mm');\n    } else {\n        return format(date, 'd.MM.yy');\n    }\n};\n\nconst Date: React.FC<MessageDateProps> = ({message, shortDate = false}) => {\n    const [dateTime, setDateTime] = React.useState<number>(0);\n\n    React.useEffect(() => {\n        if (message.updatedAt) {\n            setDateTime(message.updatedAt);\n        } else if (message.createdAt) {\n            setDateTime(message.createdAt);\n        }\n    },[]);\n\n    return (\n        <span className='message__date'>\n            {message.updatedAt && !shortDate &&\n                <p className='message__date--updateData'>\n                    {`обновлено ` + formatDistanceToNow(fromUnixTime(dateTime), {addSuffix: true, locale: ruLocale})}\n                </p>\n            }\n            {!message.updatedAt && message.createdAt && !shortDate &&\n                <p className='message__date--createData'>\n                    {`отправлено ` + formatDistanceToNow(fromUnixTime(dateTime), {addSuffix: true, locale: ruLocale})}\n                </p>\n            }\n           {shortDate &&\n                <p className='message__date--lastMessage'>\n                    {getMessageTime(fromUnixTime(dateTime))}\n                </p>\n            }\n        </span>\n    );\n}\n\nexport default Date;"],"mappings":"8IAAA,MAAOA,MAAK,KAAM,OAAO,CAEzB,OAAQC,MAAM,CAAEC,OAAO,CAAEC,YAAY,CAAEC,mBAAmB,KAAO,UAAU,CAC3E,MAAOC,SAAQ,KAAM,oBAAoB,CAAC,wFAE1C,GAAMC,eAAc,CAAG,QAAjBA,eAAc,CAAIC,IAAU,CAAa,CAC3C,GAAIL,OAAO,CAACK,IAAI,CAAC,CAAE,CACf,MAAON,OAAM,CAACM,IAAI,CAAE,OAAO,CAAC,CAChC,CAAC,IAAM,CACH,MAAON,OAAM,CAACM,IAAI,CAAE,SAAS,CAAC,CAClC,CACJ,CAAC,CAED,GAAMC,KAAgC,CAAG,QAAnCA,KAAgC,MAAqC,IAAhCC,QAAO,MAA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